package team.first.movieapiv2pro.dao.impl;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import org.springframework.stereotype.Repository;
import team.first.movieapiv2pro.dao.GenreDAO;
import team.first.movieapiv2pro.util.MongoDBUtil;

import java.util.List;

/**
 * @Author: HAPPY
 * @Project_name: project
 * @Package_name: team.first.movieapiv2pro.dao.impl
 * @Date: 2021/12/26 10:17
 * @Description:
 */
@Repository
public class GenreDAOImpl implements GenreDAO {
    @Override
    public List<DBObject> selectAll() {
        DBCollection collection = MongoDBUtil.getCollection("genre");

        // 查询
        DBCursor cursor = collection.find().sort(new BasicDBObject("id", 1));

        // 将结果转为集合
        return cursor.toArray();
    }
}
